package com.ddxz.tool.sql.struct;

import com.ddxz.tool.sql.exception.DdxzSqlEnumException;
import lombok.Getter;

import static com.ddxz.tool.sql.exception.SqlErrorStatus.INVALID_ENUM_CODE;

/**
 * class description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/8/21
 */

@Getter
public enum DdxzOperatorType {
    /**
     * SQL中通用运算符
     */
    EQ(1, " = "),
    GT(2, " > "),
    LT(3, " < "),
    UE(4, " != "),
    GE(5, " >= "),
    LE(6, " <= "),
    IN(7, " IN "),
    UIN(8, " NOT IN "),
    LIKE(9, " LIKE "),
    ULIKE(10, " NOT LIKE "),
    BETWEEN(11, " BETWEEN "),
    UBETWEEN(12, " NOT BETWEEN "),
    NULL(13, " IS NULL "),
    UNULL(14, " IS NOT NULL ");

    private int code;

    private String value;

    DdxzOperatorType(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public static DdxzOperatorType getTypeByCode(int code) {
        for(DdxzOperatorType type : values()) {
            if(type.getCode() == code) {
                return type;
            }
        }

        throw new DdxzSqlEnumException(INVALID_ENUM_CODE, code, 1, values().length);
    }
}